<?php
session_start();
header('Content-type: text/html; charset=utf-8');
require_once"lib/functions.php";
require_once"mysql.php";  
if ($_SESSION['status']!=1&&$_SESSION['status']!=24031994){
	header("Location: index.php");
}else if (!($_SESSION['user_id'])){
	header("Location: index.php");
}else{

echo'<head>
<title>Web-site</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="wrapper">
  <div id="header"><h1>Web-site</h1></div>
  <div id="navigation"> Navigation Here </div>
<div id="leftcolumn"><b>
	<p>Контактная информация</p></b>
	<p>Адрес: </p>
	<p>Телефон: </p>';
	//require_once"menu.html";  	
	require_once"LeftPanel.php";
	//echo"<p><a href = 'register.php'>Регистрация</a></p>";
	echo'</div>  
	<div id="content">';
	echo "<h2>Предыдущие показания счетчиков</h2>";
	$result =  mysql_query ("SELECT * FROM counters_type ORDER BY id") or die ("<b>Query failed:</b> " . mysql_error());
	
	echo "<table border='1'>";
	echo "<caption>Показания счетчиков</caption>";
	echo "<tr><th>Период</th>";
	while ($row = mysql_fetch_array($result)){
		echo "<th>".$row['name']."</th>";
	};
	echo "</tr>";
		$result1 = mysql_query ("SELECT counters.counter_type, counters.counter_value, period.name FROM counters JOIN period ON counters.period=period.id WHERE counters.user_id=".$_SESSION['user_id']." ORDER BY counters.period, counters.counter_type") or die ("<b>Query failed:</b> " . mysql_error());
		$a=-1;
		echo "<tr>";
		while ($row1 = mysql_fetch_array($result1)){
		if ($a==-1){
			echo"<td>".$row1['name']."</td>";
		}elseif($a>$row1['counter_type']){
			echo"</tr><tr><td>".$row1['name']."</td>";
		};
		if (preg_match("|^[\d]+[\.]+[\d]*$|", $row1['counter_value']))
		{
		$rt=rtrim(rtrim($row1['counter_value'],'0'),'.');
		}else{
		$rt=$row1['counter_value'];
		};
		echo "<td align=right>".$rt."</td>";
		$a=$row1['counter_type'];
		};
	
	echo "</tr></table>";
		
	echo'<p><h4><a href=userCabinet.php>Назад</a></h4></p>';	
echo'</div>
	<div id="rightcolumn">';
	require_once"RightPanel.php";
echo'</div>
	<div id="footer"> This is the Footer </div> 
</div>
</body>
</html>';
}
?>